package com.mao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mao.common.BaseContext;
import com.mao.common.Result;
import com.mao.dto.DishDto;
import com.mao.entity.ShoppingCart;
import com.mao.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加菜品或者套餐到购物车
     * @param shoppingCart
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody ShoppingCart shoppingCart){
        String msg = shoppingCartService.add(shoppingCart);
        return Result.success(msg);
    }

    /**
     *  查询所有购物车数据
     * @return
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> shoppingCartList = shoppingCartService.get_list();
        return Result.success(shoppingCartList);
    }

    /**
     * 从购物车移除菜品或者套餐
     * @param shoppingCart
     * @return
     */
    //在菜单减少菜品时因为口味不同，但是没的判断所有会出bug
    @PostMapping("/sub")
    public Result<String> sub(@RequestBody ShoppingCart shoppingCart){
        String msg = shoppingCartService.sub(shoppingCart);
        return Result.success(msg);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result<String> clean(){
        shoppingCartService.clean();
        return Result.success("清空成功");
    }
}
